<?php

class Pages_Form_Contacts extends Zend_Form {

	public function init() {
		$this->setmethod('post');
		
		$locales = Zend_Controller_Front::getInstance()->getParam('bootstrap')->getOption('locales');
		$defaultLang = key($locales);
		
		$subFormName = new Zend_Form_SubForm();
        $subFormName->removeDecorator('Fieldset');
        $subFormContent = new Zend_Form_SubForm();
        $subFormContent->removeDecorator('Fieldset');
        $subFormTitle = new Zend_Form_SubForm();
        $subFormTitle->removeDecorator('Fieldset');
        
        foreach ($locales as $lang=>$value) {
        	$name = new Zend_Form_Element_Text($lang);
        	$name->setLabel(strtoupper($lang) . ' ' . _('Name:'));
        	$name->setAttrib('maxlength', '255');
        	$name->addFilters(array('StringTrim','StripTags'));
        	
        	$title = new Zend_Form_Element_Text($lang);
        	$title->setLabel(strtoupper($lang) . ' ' . _('Title:'));
        	$title->setAttrib('maxlength', '255');
        	$title->addFilters(array('StringTrim','StripTags'));
        	
        	$content = new ZFEngine_Form_Element_TinyMce($lang);
			$content->setLabel(strtoupper($lang) . ' ' . _('Content of contact:'));
			$content->setAttrib('editorOptions', array('theme' => 'advanced'));
			$content->setFilters(array('StringTrim'));
			
			if($defaultLang == $lang) {
				$title->setRequired(true);
				$content->setRequired(true);
				$name->setRequired(true);
			}
			
			$subFormTitle->addElement($title);
			$subFormContent->addElement($content);
			$subFormName->addElement($name);
        }
        
        $this->addSubForm($subFormName, 'name');
        $this->addSubForm($subFormTitle, 'title');
		$this->addSubForm($subFormContent, 'content');
		
		$published = $this->createElement('radio','published');
		$published->setLabel(_('Published:'));
		$published->setSeparator(' ');
		$published->addMultiOptions(array('1'=>_('Yes'),'0'=>_('No')));
		$published->setValue('1');
		$published->setRequired(true);
		
		$is_main = $this->createElement('radio','is_main');
		$is_main->setLabel(_('Is main contact:'));
		$is_main->setSeparator(' ');
		$is_main->addMultiOptions(array('1'=>_('Yes'),'0'=>_('No')));
		$is_main->setValue('1');
		$is_main->setRequired(true);
		
		$coord = $this->createElement('text', 'geocoord');
		$coord->setLabel(_('Position of the object:'));
		$coord->setRequired(true);
		$coord->addPrefixPath ( 'Nimblecms_Form_Decorator', 'Nimblecms/Form/Decorator', 'decorator' );
		$coord->addDecorator('Yandexmap');
		$coord->setValue('60.583333343333,56.833333343333');
		
		$submit = $this->createElement('submit', 'submit');
		$submit->setLabel(_('Save'));
		
		$this->addElements(array($published,$is_main,$coord,$submit));
		
	}
}